package com.hmyd.hmyd_android.ui;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.hmyd.hmyd_android.R;
import com.hmyd.hmyd_android.AppBasic;
import com.hmyd.hmyd_android.commons.UrlConstant;
import com.hmyd.hmyd_android.utils.ContainsEmojiEditText;
import com.hmyd.hmyd_android.utils.MyToast;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

/**
 * 意见反馈
 * 
 * @author wangc
 * 
 */
@ContentView(R.layout.activity_feedback)
public class FeedBackActivity extends BasicActivity {
	// 标题栏
	@ViewInject(R.id.home_title)
	public View home_title;
	@ViewInject(R.id.home_title_txt)
	public TextView home_title_txt;
	@ViewInject(R.id.home_right)
	public TextView home_right;

	@ViewInject(R.id.ed_feedback)
	private ContainsEmojiEditText feedBack;
	@ViewInject(R.id.feedback_phone)
	private EditText feedPhone;
	@ViewInject(R.id.feedback_name)
	private EditText feedName;

	private final int FEEDBACK = 0;

	@OnClick(R.id.feedback_submmit_btn)
	public void onClick(View view) {
		RequestParams params = new RequestParams();
		String feedback = feedBack.getText().toString().trim();
		String feedphone = feedPhone.getText().toString().trim();
		String name = feedName.getText().toString().trim();

		if (TextUtils.isEmpty(feedback)) {
			MyToast.showHMToast(FeedBackActivity.this, false, "请输入意见反馈");
			return;
		}
		if (TextUtils.isEmpty(feedphone)) {
			MyToast.showHMToast(FeedBackActivity.this, false, "请输入联系电话");
			return;
		}
		if (TextUtils.isEmpty(name)) {
			MyToast.showHMToast(FeedBackActivity.this, false, "请输入您的姓名");
			return;
		}

		params.addBodyParameter("content", feedback);
		params.addBodyParameter("telephone", feedphone);
		params.addBodyParameter("name", name);
		onRequest(FEEDBACK, UrlConstant.FEEDBACK, HttpMethod.GET, params);
	}

	@Override
	protected void onResume() {
		super.onResume();

	}

	@Override
	public void onPostSuccess(int postId, String msg) {
		MyToast.showHMToast(FeedBackActivity.this, true, "意见反馈成功");
		finish();
	}

	@Override
	public void onPostFailure(int postId, String msg) {

	}

	@Override
	protected void setParams() {
		home_title_txt.setText("意见反馈");
		home_title.setOnTouchListener(touch);
	}

	@Override
	protected void leftButton() {
		AppBasic.getInstance().finishCurrentActivity();
	}

	@Override
	protected void rightButton() {

	}

}
